﻿namespace Quail
{
    /// <summary>
    /// The status of a log entry
    /// </summary>
    public enum LogStatus
    {
        /// <summary>
        /// Invalid log status
        /// </summary>
        Invalid = 0,

        /// <summary>
        /// Item passed
        /// </summary>
        Pass = 1,

        /// <summary>
        /// Item failed
        /// </summary>
        Fail = 2,

        /// <summary>
        /// Information only
        /// </summary>
        Information = 3,

        /// <summary>
        /// Warning message
        /// </summary>
        Warning = 4,

        /// <summary>
        /// A navigation occurred
        /// </summary>
        Navigate = 5,

        /// <summary>
        /// A screenshot
        /// </summary>
        Screenshot = 6,

        /// <summary>
        /// Test startup
        /// </summary>
        Startup = 7,

        /// <summary>
        /// Status is pending
        /// </summary>
        Pending = 8,

        /// <summary>
        /// Status is a result of something
        /// </summary>
        Result = 9,

        /// <summary>
        /// Status implies the task was rolled back
        /// </summary>
        Rollback = 10,

        /// <summary>
        /// The task was abandoned due to not explicitly calling Finish() or Rollback()
        /// </summary>
        Abandoned = 11,

        /// <summary>
        /// The task failed due to a YSOD
        /// </summary>
        FailYsod = 12,

        /// <summary>
        /// The task failed due to a timeout, see also FailSync
        /// </summary>
        FailTimeout = 13,

        /// <summary>
        /// A specific type of timeout failure when a Sync() doesn't complete in a timely manner
        /// </summary>
        FailSync = 14,

        /// <summary>
        /// Failed due to a 3rd party problem
        /// </summary>
        FailThirdParty = 15,

        /// <summary>
        /// Failed due to an internal Quail problem
        /// </summary>
        FailQuail = 16,

        /// <summary>
        /// Pending Async call
        /// </summary>
        PendingAsync = 17
    }

    /// <summary>
    /// Extension methods to the LogStatus enumeration
    /// </summary>
    public static class LogStatusExtension
    {
        /// <summary>
        /// Returns true if the LogStatus is a type of failing status (Fail, FailYSOD, FailSync, FailTimeout, FailThirdParty, FailQuail, Abandoned)
        /// </summary>
        /// <param name="status">The status to check</param>
        /// <returns></returns>
        public static bool IsFailingStatus(this LogStatus status)
        {
            return status == LogStatus.Fail ||
                   status == LogStatus.FailQuail ||
                   status == LogStatus.FailYsod ||
                   status == LogStatus.FailSync ||
                   status == LogStatus.FailThirdParty ||
                   status == LogStatus.FailTimeout;
        }
    }
}
